package com.taylor.community.controller;

import com.taylor.community.util.CommunityUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/common")
public class CommonController {
//cookie实例
    @RequestMapping(path = "/cookie/set",method = RequestMethod.GET)
    @ResponseBody//表示返回不是页面资源而是json格式的数据
    public String setCookie(HttpServletResponse response){
        //创建Cookie
        Cookie cookie = new Cookie("code", CommunityUtil.generateUUID());
        //设置cookie生效范围
        cookie.setPath("/community/");
        //设置cookie有效时间
        cookie.setMaxAge(60 * 10);
        //将cookie存到response中
        response.addCookie(cookie);
        return "set Cookie";
}
}
